package com.eco.fanliapp.controller.app;


import com.eco.fanliapp.common.base.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.AppUser;
import com.eco.fanliapp.service.ISyUserUnboundedOrderApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-12-19
 */
@RestController
@RequestMapping("/app/unboundedOrder")
public class SyUserUnboundedOrderApplyController extends BaseController {

    @Autowired
    private ISyUserUnboundedOrderApplyService syUserUnboundedOrderApplyService;

    @GetMapping("/addUnboundedOrder")
    @ResponseBody
    public ServerResponse addUnboundedOrder(String orderId) {
        AppUser appUser = getAppUser();
        if (null == appUser) {
            return ServerResponse.createByErrorCodeMessage(301, "Token不正确");
        }
        Long orderIdLong = null;
        try {
            orderIdLong = Long.parseLong(orderId);
        } catch (Exception e) {
            return ServerResponse.createByErrorMessage("请输入正确的订单号");
        }
        return syUserUnboundedOrderApplyService.addUnboundedOrder(orderIdLong, appUser);
    }

    @GetMapping("/getUnboundedOrderList")
    @ResponseBody
    public ServerResponse getUnboundedOrderList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize) {
        AppUser appUser = getAppUser();
        if (null == appUser) {
            return ServerResponse.createByErrorCodeMessage(301, "Token不正确");
        }
        return syUserUnboundedOrderApplyService.getUnboundedOrderList(appUser,pageNum,pageSize);
    }


}
